<?php

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
class Admin extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = true;

    public function authGroupAccess()
    {
        return self::belongsTo(AuthGroupAccess::class, 'id', 'uid')->bind(['group_id']);
    }

    public function authGroup()
    {
        return self::belongsTo(AuthGroup::class, 'group_id')->bind(['name']);
    }
    public function getLastLoginTimeAttr($value)
    {
        return date('Y-m-d H:i:s',$value);
    }
    public static function getAdminList($where = 0)
    {
        return self::with(['authGroupAccess','authGroup'])->whereOr($where)->withoutField('plain_code,password')->order('id DESC')->paginate();
    }
    protected function getSexAttr($value)
    {
        $sex = ['保密','男','女'];
        return $sex[$value];
    }
}